package com.hj.demo.homework;

public class Test4 {
    public static void main(String[] args) {
        Hero hero1 = new Hero("小明", 100, 99);
        Hero hero2 = new Hero("小红", 10, 60);
        System.out.println(hero1.getName()+"开始攻击");
        hero1.attack();
        System.out.println(hero2.getName()+"开始攻击");
        hero2.attack();
    }
}
class Hero implements Fightable{
    public String name;
    public int level;
    public int experience;
    public int blood=100;
    public static final int min=10;

    public Hero(String name, int level, int experience) {
        this.name = name;
        this.level = level;
        this.experience = experience;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getExperience() {
        return experience;
    }

    public void setExperience(int experience) {
        this.experience = experience;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    @Override
    public void attack() {
        if (fightOver()){
            System.out.println("胜利");
            experience++;
            System.out.println("经验值增加："+experience);
        }else {
            System.out.println("失败");
        }
        System.out.println();
    }

    @Override
    public boolean fightOver() {
        int a =this.blood-this.level;
        if (a<=min){
            System.out.println("危险");
        }
        return a <= 0;
    }
}
interface Fightable{
    void attack();
    boolean fightOver();
}